<script setup lang="ts">
import { ref } from 'vue'
//import lQrcode from './components/l-qrcode/l-qrcode.vue'
import { useDeviceStore } from '@/stores'
import prileInfo from '@/components/prile-info.vue'
import { getQrCodeApi } from '@/services/equipment'
const deviceStore = useDeviceStore()
const show = ref(false)
//const val = ref('')
const baseUrl = 'https://szsensing.com:8581/'
const qrimg = ref('')
const popup = ref<UniHelper.UniPopupInstance>()
//app端是json字符串，所以为了都能识别，上传生成时也用json
const showqr = async (deviceNum: string) => {
  const res = await getQrCodeApi(JSON.stringify({ app: 'SC500', deviceNum }))
  qrimg.value = baseUrl + res.data
  popup.value?.open()
  /* val.value = JSON.stringify({
    deviceNum,
  }) */
}

const isRefresh = ref(false)
const onRefresh = async () => {
  console.log('刷新')
  isRefresh.value = true
  await deviceStore.getDeviceList()
  isRefresh.value = false
}
const back = () => {
  uni.navigateBack({
    delta: 1,
  })
}
</script>
<template>
  <view class="equipment-container">
    <scroll-view
      scroll-y
      class="scroll-view"
      :refresher-enabled="true"
      @refresherrefresh="onRefresh"
      :refresher-triggered="isRefresh"
    >
      <prile-info
        :picture="item.picture"
        :deviceNum="item.deviceNum"
        :id="item.id"
        :name="item.name"
        v-for="item in deviceStore.deviceList"
        :key="item.id"
        :rightArrow="true"
        @showqr="showqr"
      ></prile-info>
    </scroll-view>
    <uni-popup ref="popup" type="center" background-color="#fff">
      <img :src="qrimg" alt="" style="width: 384.615rpx; height: 384.615rpx" />
    </uni-popup>
  </view>
</template>
<style lang="scss">
page {
  height: 100vh;
  font-family: PingFangSC-regular;
  overflow: hidden;
  .equipment-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: #f8f8f8;
    .scroll-view {
      height: calc(100vh - 115.385rpx - 34.615rpx - 38.462rpx);
      margin-top: 38.462rpx;
      overflow: hidden;
      .placeholder {
        height: 19.231rpx;
      }
    }
    .u-safe-bottom {
      display: none !important ;
    }
  }
}
</style>
